//
//  SystemSetupVc.m
//  FindJob
//
//  Created by apple on 16/3/11.
//  Copyright © 2016年 Lee. All rights reserved.
//

#import "SystemSetupVc.h"
#import "SwitchCell.h"
#import "DefaultCell.h"

static NSString *const kReusableSwitchCell = @"switchcell";
static NSString *const kReusableDefaultCell = @"defaultcell";



@interface SystemSetupVc ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, copy) NSArray *sectionTitles;
 - (void)initializeDataSource;     /**< 初始化数据源 */
 - (void)initializeUserIntefcace;  /**< 初始化用户界面 */
@end

@implementation SystemSetupVc

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeDataSource];
    [self initializeUserIntefcace];
}
- (void)initializeDataSource{
    self.sectionTitles = @[@"推送通知",@"账户设置",@"分享设置",@"将你喜欢的这款应用分享给你的朋友吧"];
}
- (void)initializeUserIntefcace{
    UINib *switchCellNib = [UINib nibWithNibName:NSStringFromClass([SwitchCell class]) bundle:nil];
    [self.tableView registerNib:switchCellNib forCellReuseIdentifier:kReusableSwitchCell];
    
    
    UINib *defaultCellNib = [UINib nibWithNibName:NSStringFromClass([DefaultCell class]) bundle:nil];
    [self.tableView registerNib:defaultCellNib forCellReuseIdentifier:kReusableDefaultCell];
}
#pragma mark - <UITableViewDelegate,UITableViewDataSource>
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0 || section == 1) {
        return 1;
    }else if(section == 2){
        return 2;
    }else{
        return 0;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        SwitchCell *cell = [tableView dequeueReusableCellWithIdentifier:kReusableSwitchCell];
        cell.nameLabel.text = @"推送通知";
        cell.switchControl.tag = indexPath.section + indexPath.row;
        return cell;
    }
    if(indexPath.section == 1 && indexPath.row == 0){
        DefaultCell *cell = [tableView dequeueReusableCellWithIdentifier:kReusableDefaultCell];
        cell.nameLabel.text = @"修改密码";
       
        return cell;
    }
    if(indexPath.section == 2){
        SwitchCell *cell = [tableView dequeueReusableCellWithIdentifier:kReusableSwitchCell];
        if (indexPath.row == 0) {
             cell.nameLabel.text = @"新浪微博";
            cell.switchControl.tag = indexPath.section + indexPath.row;
        }
        if(indexPath.row == 1){
            cell.nameLabel.text = @"腾讯微博";
            cell.switchControl.tag = indexPath.section + indexPath.row;
        }
        return cell;
    }
    
    return nil;
}
-  (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, CGRectGetWidth(self.view.bounds)- 20, 40)];
    label.font = [UIFont boldSystemFontOfSize:18];
    label.textAlignment = NSTextAlignmentLeft;
    label.text = _sectionTitles[section];
    label.textColor = [UIColor blackColor];
    
    UIView *titeView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 40)];
    [titeView addSubview:label];
    return titeView;
}
@end
